﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.ObjectBuilder2;
using Lilium.Web.Mvc;

namespace Lilium.Unity.MvcHttpApplication
{
	/// <summary>
	/// Reflects entity filters and registers corresponding providers in 
	/// </summary>
	// вообще можно же только политикой обойтись.
	public sealed class EntityFilterConfigurationStrategy: BuilderStrategy
	{
		public EntityFilterConfigurationStrategy()
		{
		}

		public override void PreBuildUp(IBuilderContext context)
		{
			if (context == null) throw new ArgumentNullException("context");

			var typeToBuild = context.BuildKey.Type;
		
			if (typeof(EntityController).IsAssignableFrom(typeToBuild))
			{
				var configurationPolicy = context.Policies.Get<IEntityFilterConfigurationPolicy>(context.BuildKey);
				if (configurationPolicy != null)
				{
					configurationPolicy.ConfigureEntityFilter(context);
				}
			}
		}
	}
}